package com.art.sunflower.service.impl;

import com.art.sunflower.exception.NullIntroduceException;
import com.art.sunflower.exception.NullNewsException;
import com.art.sunflower.mapper.IntroduceMapper;
import com.art.sunflower.pojo.SchoolIntroduce;
import com.art.sunflower.service.IntroduceService;
import com.art.sunflower.util.MyPageInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class IntroduceServiceImpl implements IntroduceService {

    @Resource
    IntroduceMapper introduceMapper;

    @Override
    public MyPageInfo findAllIntroduce(Integer pageSize, Integer pageNo) throws NullIntroduceException {
        PageHelper.startPage(pageNo, pageSize);
        List<Map<String, Object>> introduce = introduceMapper.findAllIntroduce();
        if (introduce.size() == 0)
            throw new NullNewsException();
        for (Map<String, Object> stringObjectMap : introduce) {
            stringObjectMap.remove("id");
        }
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(introduce);
        return new MyPageInfo(pageInfo);
    }

    @Override
    public int updateIntroduceById(SchoolIntroduce schoolIntroduce) {
        return introduceMapper.updateIntroduceById(schoolIntroduce);
    }

    @Override
    public SchoolIntroduce selectById(int id) {
        return introduceMapper.selectById(id);
    }
}
